package cn.t.enums.order;


import cn.t.core.enums.Enumer;
import cn.t.core.enums.base.CommonEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author l
 */
@Enumer
@Getter
@AllArgsConstructor
public enum ErrorTypeEnum  implements CommonEnum<Integer, String> {
    ERROR2(0, "正常领用"),
    ERROR3(-1, "领料超时"),
    ERROR4(-2, "货道硬件损坏"),
 //   ERROR5(-3, "无商品货道重量减少"),货道未上架商品
 //超出误差范围与疑似未领取区别，一个是by订单，一个是领取了商品，部分行是未领取状态
    ERROR6(-4, "超出误差范围"),
    ERROR7(-5, "货道增重"),
    ERROR8(-6, "商品重量未维护或者为0"),
    ERROR9(-7, "零库存领取"),
    ERROR10(-8, "疑似未领取"),
    ERROR11(-9, "补货货道重量减少"),
    ERROR12(-10, "补货货道货品库存为负数"),
    //ERROR13(-11, "补货时未检测到库存增加"),
    ERROR14(-12, "补货超时"),
    ERROR15(-13, "开门后未传重量数据"),
    ERROR16(-14, "关门后未传重量数据"),
    //== 开门后未传重量数据  关门后未传重量数据
    ERROR17(-15, "开关门两次数据长度不等"),
    //ERROR18(-16, "重力数量未获取到"),
    ERROR19(-17, "开门后上传重量数据长度大于1"),
    ERROR20(-18, "补货货道重量减少"),

    ERROR21(-19, "非计划补货货道增重"),

    ERROR22(-20, "货道未上架商品"),
    ERROR23(-21, "货道数据未获取到"),
    ERROR24(-22, "疑似未补货"),
    ERROR25(-25, "开门后未关门"),
    ERROR27(-27, "领料中断"),
    ERROR26(-26, "未知错误"),
    ERROR28(-28, "非计划补货货道补货"),;

    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;
    public static String getDescByKey(Integer key) {
        Optional<ErrorTypeEnum> first = Arrays.stream(values()).filter(f -> f.getCode().equals(key)).findFirst();
        if (first.isPresent()) {
            return first.get().getName();
        }
        return "";
    }

    public static String getDescByKey(Set<Integer> keys) {
        return Arrays.stream(values()).filter(f -> keys.contains(f.getCode())).map(ErrorTypeEnum::getName).collect(Collectors.joining(","));
    }
}
